<template>
    <view>
        <!-- index.wxml -->
		<uni-section shadow title="" subTitle="使用 shadow 属性启用阴影" type="line" style="margin-bottom: 3px;">
			<view class="box-bg">
				<uni-nav-bar   backgroundColor="#ff6e00"/>
			</view>
		</uni-section>
		
        <view class="header">
            <view class="top">
                <view class="left">
					{{storeName}}
                    <!-- <image :src="avatar" /> -->
                </view>
                <view class="center">
                    <!-- <view class="title">{{ perInfo.nickName }}</view> -->
                    <!-- <view class="subtitle">海底捞陆家嘴商圈购物中心店</view> -->
                </view>
               <!-- <view class="right">
                    <image src="/static/images/sz.png" mode="" />
                </view> -->
            </view>

            <view class="bigicon">
				
					<view class="list" @tap="noOpen">
					    <image src="/static/images/sk.png" mode="" />
					    <view class="title">收 款</view>
					</view>
					<view class="list" @tap="noOpen">
					    <image src="/static/images/hx.png" mode="" />
					    <view class="title">核 销</view>
					</view>
					<view class="list" @tap="noOpen">
					    <image src="/static/images/sp.png" mode="" />
					    <view class="title">商 品</view>
					</view>
					<view class="list" @tap="noOpen">
					    <image src="/static/images/dd.png" mode="" />
					    <view class="title">订 单</view>
					</view>
                
            </view>
        </view>
        <view class="box">
            <view class="title">
                <image src="/static/images/bttb.png" mode="" />
                <block>门店管理</block>
            </view>
            <view class="item">
                <view class="list" @tap="goOther">
                    <image src="/static/images/item1.png" mode="" />
                    <view class="subtitle">收银流水</view>
                </view>
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item2.png" mode="" />
                    <view class="subtitle">营业报表</view>
                </view>
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item3.png" mode="" />
                    <view class="subtitle">数据报表</view>
                </view>
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item4.png" mode="" />
                    <view class="subtitle">到帐查询</view>
                </view>
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item5.png" mode="" />
                    <view class="subtitle">开具发票</view>
                </view>
                <!-- <view class="list">
      <image src="/images/item6.png" mode="" />
      <view class="subtitle">
        老板助手
      </view>
    </view> -->
	<!-- @tap="goshop"  -->
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item6.png" mode="" />
                    <view class="subtitle">系统设置</view>
                </view>
            </view>
            <view></view>
        </view>

        <view class="box">
            <view class="title">
                <image src="/static/images/bttb.png" mode="" />
                <block>营销管理</block>
            </view>
            <view class="item">
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item8.png" mode="" />
                    <view class="subtitle">会员管理</view>
                </view>
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item9.png" mode="" />
                    <view class="subtitle">次卡核销</view>
                </view>
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item10.png" mode="" />
                    <view class="subtitle">商城管理</view>
                </view>
                <view class="list"  @tap="goOther">
                    <image src="/static/images/item11.png" mode="" />
                    <view class="subtitle">外卖管理</view>
                </view>
            </view>
            <view></view>
        </view>

        <view class="box">
            <view class="title">
                <image src="/static/images/bttb.png" mode="" />
                <block>物业服务</block>
            </view>
            <view class="item">
                <view class="list" @tap="goCar">
                    <image src="/static/images/item12.png" mode="" />
                    <view class="subtitle">停车费</view>
                </view>
                <view class="list" @tap="goShuiFei">
                    <image src="/static/images/item13.png" mode="" />
                    <view class="subtitle">水费</view>
                </view>
                <view class="list" @tap="goDianFei">
                    <image src="/static/images/item14.png" mode="" />
                    <view class="subtitle">电费</view>
                </view>
               <!-- <view class="list" @tap="goRanqiFei">
                    <image src="/static/images/item15.png" mode="" />
                    <view class="subtitle">燃气费</view>
                </view> -->
                <view class="list" @tap="goZujin">
                    <image src="/static/images/item16.png" mode="" />
                    <view class="subtitle">租金物业</view>
                </view>
                <view class="list" @tap="goOther">
                    <image src="/static/images/item17.png" mode="" />
                    <view class="subtitle">其他交费</view>
                </view>
                <view class="list" @tap="goBaoxiu">
                    <image src="/static/images/item18.png" mode="" />
                    <view class="subtitle">报修报检</view>
                </view>
                <view class="list" @tap="goFapiao">
                    <image src="/static/images/item19.png" mode="" />
                    <view class="subtitle">电子发票</view>
                </view>
            </view>
            <view></view>
        </view>

        <!-- 中间弹窗 -->
        <view class="popup-box" v-if="firstLoginFlag == 0" @tap="closePopup"></view>
        <view class="info-center" v-if="firstLoginFlag == 0">
            <view>
                <view class="row-info">
                    <view class="tip">首次登录请重设密码，修改后忘记密码请联系管理员重置</view>
                    <form @submit="formSubmit" @reset="">
                        <view class="title">旧密码</view>
                        <view class="text_section">
                            <input placeholder="请输入旧密码" name="oldPassword" :type="open ? 'password' : 'text'" placeholder-style="color:#999;" class="password" />
                            <image class="eye" :src="open ? '/images/eye-hidden.png' : '/images/eye-show.png'" @tap="show"></image>
                        </view>
                        <view class="title">新密码</view>
                        <view class="text_section">
                            <input placeholder="请输入新密码" name="newPassword" :type="open1 ? 'password' : 'text'" placeholder-style="color:#999;" class="password" />
                            <image class="eye" :src="open1 ? '/images/eye-hidden.png' : '/images/eye-show.png'" @tap="show1"></image>
                        </view>
                        <view class="title">确认密码</view>
                        <view class="text_section">
                            <input placeholder="请输入确认密码" name="confirmPassword" :type="open2 ? 'password' : 'text'" placeholder-style="color:#999;" class="password" />
                            <image class="eye" :src="open2 ? '/images/eye-hidden.png' : '/images/eye-show.png'" @tap="show2"></image>
                        </view>
                        <button formType="submit" class="row-btn" :disabled="btn">确认</button>
                    </form>
                </view>
            </view>
        </view>

        <navigation navId="1" />
    </view>
</template>

<script>
const app = getApp();
const $http = app.globalData.$http;
var config = require('../../utils/config');
const FormData = require('../../utils/formData.js');
export default {
    data() {
        return {
            picUrl: config.Config,
            perInfo: {
                nickName: ''
            },
            avatar: '',
            firstLoginFlag: false,
            open: true,
            open1: true,
            open2: true,
            btn: false,
            firstLoginFlag: 1,
			storeName:""
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
		
		const token = uni.getStorageSync('token');
		if (!token) {
		  // 若未登录，跳转到登录页
		  uni.reLaunch({
			url: '/pages/login/index'
		  });
		}else{
			this.getInfo();
		}
			
        
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        show() {
            this.setData({
                open: !this.open
            });
        },

        show1() {
            this.setData({
                open1: !this.open1
            });
        },

        show2() {
            this.setData({
                open2: !this.open2
            });
        },

        formSubmit: function (e) {
            const that = this;
            const reg = /^[\S]{5,18}$/;
            if (e.detail.value.oldPassword == '') {
                uni.showToast({
                    title: '请输入旧密码',
                    icon: 'none'
                });
                return;
            } else if (e.detail.value.newPassword == '') {
                uni.showToast({
                    title: '请输入新密码',
                    icon: 'none'
                });
                return;
            } else if (!reg.test(e.detail.value.newPassword)) {
                uni.showToast({
                    title: '密码必须为5-18位非空白字符',
                    icon: 'none'
                });
                return;
            } else if (e.detail.value.confirmPassword == '') {
                uni.showToast({
                    title: '请输入确认密码',
                    icon: 'none'
                });
                return;
            } else if (e.detail.value.confirmPassword != e.detail.value.newPassword) {
                uni.showToast({
                    title: '两次输入密码不一致',
                    icon: 'none'
                });
                return;
            }
            that.setData({
                btn: true
            });
            let formData = new FormData();
            formData.append('oldPassword', e.detail.value.oldPassword);
            formData.append('newPassword', e.detail.value.newPassword);
            formData.append('confirmPassword', e.detail.value.confirmPassword);
            $http.updatePassword(formData).then((res) => {
                if (res.code == 200) {
                    that.setData({
                        btn: false,
                        firstLoginFlag: 1
                    });
					
					// 新增提示和退出逻辑
					uni.showToast({
						title: '密码修改成功，退出重新登录', // 修改提示内容
						icon: 'none',
						duration: 2000 
					});
			 
					// 延迟执行退出操作（确保提示信息能被用户看到）
					setTimeout(() => {
						// 退出登录并跳转到登录页（根据你的实际业务逻辑调整）
						uni.reLaunch({
							url: '/pages/login/index'
						});
					}, 2000); // 与提示显示时间一致
                } else {
                    that.setData({
                        btn: false,
                        firstLoginFlag: 1
                    });
                    uni.showToast({
                        title: res.msg,
                        icon: 'none'
                    });
                }
            });
        },

        getInfo: function () {
            const that = this;
            $http.getInfo({}).then((res) => {
                if (res.code == 200) {
					console.log('获取登录用户的个人信息',res);
					// 水电权限
					uni.setStorageSync('publicService', res.user.publicService);
					// 停车费权限
					uni.setStorageSync('paymentType', res.user.paymentType);
					this.storeName = res.user.nickName;
                    that.setData({
                        perInfo: res.user,
                        firstLoginFlag: res.user.firstLoginFlag,
                        avatar: this.picUrl + res.user.avatar
                    });
                }
                // else{
                //   wx.showToast({
                //     title: res.msg,
                //     icon: 'error'
                //   })
                // }
            });
        },

        goCar: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
				// 判断是否有权限 无权限02、包时 00、包月01
				// console.log('打印停车权限：',uni.getStorageSync('paymentType'));
				if (uni.getStorageSync('paymentType')=='02' ) {
				    uni.showToast({
				        title: '无权限，请联系商管！',
				        icon: 'none'
				    });
				    return;
				}else{
					uni.reLaunch({
						url: '/pages/carnumber/index?merchantCode=' + this.perInfo.merchantCode
					});
				}
            }
        },

        goShuiFei: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
				// 水费，电费，暂停状态下，提示：物业服务已暂停，请联系商管！燃气不做判断。
				// 判断是否暂停
				this.publicService = uni.getStorageSync('publicService');
				
				if (this.publicService === '1') {
				    uni.showToast({
				        title: '物业服务已暂停，请联系商管！',
				        icon: 'none'
				    });
				    return;
				} else {
					uni.reLaunch({
						url: '/pages/shuiFei/index?merchantCode=' + this.perInfo.merchantCode
					});
				}
            }
        },

        goDianFei: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
				// 水费，电费，暂停状态下，提示：物业服务已暂停，请联系商管！燃气不做判断。
				// 判断是否暂停
				this.publicService = uni.getStorageSync('publicService');
				
				if (this.publicService === '1') {
				    uni.showToast({
				        title: '物业服务已暂停，请联系商管！',
				        icon: 'none'
				    });
				    return;
				} else {
					uni.reLaunch({
						url: '/pages/dianFei/index?merchantCode=' + this.perInfo.merchantCode
					});
				}	
            }
        },

        goRanqiFei: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
                uni.reLaunch({
                    url: '/pages/ranqiFei/index'
                });
            }
        },

        goZujin: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
                // uni.reLaunch({
                //     url: '/pages/zujin/index'
                // });
				uni.showToast({
					title: '功能暂未开通',
					icon: 'none'
				});
            }
        },

        goOther: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
                // uni.reLaunch({
                //     url: '/pages/other/index'
                // });
				uni.showToast({
					title: '功能暂未开通',
					icon: 'none'
				});
            }
        },

        goBaoxiu: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
                // uni.reLaunch({
                //     url: '/pages/baoxiu/index'
                // });
				uni.showToast({
					title: '功能暂未开通',
					icon: 'none'
				});
            }
        },
		
		noOpen: function () {
		    if (uni.getStorageSync('token') == '') {
		        uni.showToast({
		            title: '您还未登录，请先登录',
		            icon: 'none'
		        });
		        setTimeout(function () {
		            uni.navigateTo({
		                url: '/pages/login/index'
		            });
		        }, 1200);
		    } else {
		        
				uni.showToast({
					title: '功能暂未开通',
					icon: 'none'
				});
		    }
		},

        goFapiao: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
                uni.reLaunch({
                    url: '/pages/fapiaoAndOrder/index'
                });
            }
        },

        goshop: function () {
            if (uni.getStorageSync('token') == '') {
                uni.showToast({
                    title: '您还未登录，请先登录',
                    icon: 'none'
                });
                setTimeout(function () {
                    uni.navigateTo({
                        url: '/pages/login/index'
                    });
                }, 1200);
            } else {
                uni.reLaunch({
                    url: '/pages/shop/index'
                });
            }
        },

        closePopup() {
            console.log('占位：函数 closePopup 未声明');
        }
    }
};
</script>
<style>
/**index.wxss**/

.header {
    width: 100%;
    background-color: #ff6e00;
	padding-bottom:10rpx;
}

.header .top {
    width: 96%;
    margin: 0 auto;
    height: 140rpx;
    /* background-color: #fff; */
    border-radius: 30rpx;
    padding: 0 20rpx;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header .top .left {
    width: 80%;
    height: 100rpx;
}

.header .top .left image {
    width: 100rpx;
    height: 100rpx;
    border-radius: 50%;
}

.header .top .center {
    width: 560rpx;
    padding: 20rpx;
    box-sizing: border-box;
}

.header .top .center .title {
    /* color: rgb(0, 33, 80); */
	color: rgb(250, 42, 42);
    font-size: 28rpx;
    font-weight: 500;
    line-height: 40rpx;
}

.header .top .center .subtitle {
    color: rgb(0, 0, 0);
    font-size: 34rpx;
    font-weight: 400;
    line-height: 34rpx;
    margin-top: 10rpx;
	margin-left:-150rpx;
}

.header .top .right {
}

.header .top .right image {
    width: 48rpx;
    height: 48rpx;
}

.bigicon {
    display: flex;
    width: 96%;
    margin: 0 auto;
    padding: 20rpx 0;
	background-color: rgba(255, 255, 255, 0.6);
	border-radius:8rpx;
}

.bigicon .list {
    width: 25%;
}

.bigicon .list image {
    width: 70rpx;
    height: 70rpx;
    display: block;
    margin: 0 auto;
}

.bigicon .list .title {
    /* color: rgb(249, 249, 249); */
	color: rgb(250, 42, 42);
    font-size: 28rpx;
    font-weight: 400;
    text-align: center;
    margin-top: 14rpx;
}

/***/
.box {
    border: 2rpx solid rgb(166, 166, 166);
    border-radius: 16rpx;
    width: 710rpx;
    margin: 0 auto;
    padding: 10rpx 20rpx;
    box-sizing: border-box;
    margin-top: 30rpx;
}

.box .title {
    color: #ff6e00;
    display: flex;
    align-items: center;
    font-size: 28rpx;
    margin-bottom: 10rpx;
}

.box .title image {
    width: 30rpx;
    height: 30rpx;
    margin-right: 10rpx;
    display: block;
}

.item {
    display: flex;
    flex-wrap: wrap;
}

.item .list {
    width: 25%;
    padding: 10rpx 0rpx;
    width: 25%;
}

.item .list image {
    width: 60rpx;
    height: 60rpx;
    display: block;
    margin: 0 auto;
}

.item .list .subtitle {
    color: #4d4d4d;
    font-size: 26rpx;
    font-weight: 400;
    text-align: center;
    margin-top: 14rpx;
}

/* 蒙层 */
.popup-box {
    position: fixed;
    z-index: 9999;
    top: 0;
    background-color: rgba(0, 0, 0, 0.7);
    width: 100%;
    height: 100%;
}

/* 中 */
.info-center {
    position: fixed;
    z-index: 999999;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10rpx;
    width: 700rpx;
    left: 25rpx;
    top: 100rpx;
    padding: 40rpx;
    box-sizing: border-box;
}

.tip {
    color: #fe725c;
    font-size: 28rpx;
}

.row-btn {
    width: 100%;
    height: 80rpx;
    line-height: 80rpx;
    background-color: #fe725c;
    text-align: center;
    color: #fff;
    border-radius: 8rpx;
    margin-top: 100rpx;
}

.row-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 15rpx;
}

.title {
    width: 100%;
    font-size: 30rpx;
    font-weight: 900;
    color: #c1c7d0;
    /* margin: 30rpx auto 20rpx auto; */
}

.text_section {
    width: 610rpx;
    margin: 0 auto;
    position: relative;
    display: flex;
    align-items: center;
}

.text_section input {
    width: 100%;
    height: 100rpx;
    color: #333;
    font-size: 28rpx;
    position: relative;
    z-index: 2;
    background-color: #f7f7f7;
    border-radius: 8rpx;
    padding: 20rpx;
    box-sizing: border-box;
}

.eye {
    width: 60rpx;
    height: 60rpx;
    position: absolute;
    top: 24rpx;
    right: 10rpx;
    z-index: 9999;
}

.text_section .password {
    padding-right: 75rpx;
}
</style>
